import { TextLoader } from "langchain/document_loaders/fs/text";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { NomicEmbeddings } from "./utils/embed2.js";

const loader = new TextLoader("data/kong.txt");

const docs = await loader.load();

const splitter = new RecursiveCharacterTextSplitter({
  chunkSize: 300,
  chunkOverlap: 0,
});

const splittedDocs = await splitter.splitDocuments(docs);

const texts = splittedDocs.map((doc) => doc.pageContent);

// console.log(texts)

const embeddings = new NomicEmbeddings(5);

// 开始计时
const startTime = performance.now();

const result = await embeddings.embedDocuments(texts);

console.log(`向量化结果：`, result);

// 计时结束
const endTime = performance.now();
console.log(`总耗时：${endTime - startTime} 毫秒`);
